<?php
namespace Plugin\Message\Schema;

use Plugin\Message\Model\Message;
use Hyperf\Swagger\Annotation\Property;
use Hyperf\Swagger\Annotation\Schema;

/**
 * 消息表
 */
#[Schema(title: 'MessageSchema')]
class MessageSchema implements \JsonSerializable
{
    #[Property(property: 'id', title: '消息ID', type: 'bigint')]
    public string $id;

    #[Property(property: 'type', title: '消息类型1预警2反馈3系统', type: 'int')]
    public string $type;

    #[Property(property: 'title', title: '消息标题', type: 'string')]
    public string $title;

    #[Property(property: 'content', title: '消息内容', type: 'text')]
    public string $content;

    #[Property(property: 'extra', title: '额外信息', type: 'json')]
    public string $extra;

    #[Property(property: 'related_id', title: '关联ID', type: 'int')]
    public string $related_id;

    #[Property(property: 'level', title: '消息级别1普通2重要3紧急', type: 'tinyint')]
    public string $level;

    #[Property(property: 'created_at', title: 'created_at', type: 'datetime')]
    public string $created_at;

    #[Property(property: 'updated_at', title: 'updated_at', type: 'datetime')]
    public string $updated_at;

    #[Property(property: 'deleted_at', title: 'deleted_at', type: 'datetime')]
    public string $deleted_at;




    public function __construct(Message $model)
    {
       $this->id = $model->id;
       $this->type = $model->type;
       $this->title = $model->title;
       $this->content = $model->content;
       $this->extra = json_encode($model->extra);
       $this->related_id = $model->related_id;
       $this->level = $model->level;
       $this->created_at = $model->created_at;
       $this->updated_at = $model->updated_at;
       $this->deleted_at = $model->deleted_at;

    }

    public function jsonSerialize(): array
    {
        return [
            'id' => $this->id,
            'type' => $this->type,
            'title' => $this->title,
            'content' => $this->content,
            'extra' => $this->extra,
            'related_id' => $this->related_id,
            'level' => $this->level,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at
        ];
    }
}